<template>
  <div class="locate-q">
    <div class="content">
      <n-thing content-indented>
        <template #header>
          <n-row class="title">
            <div class="index" v-if="props.index">{{ props.index + '.' }}</div>
            <div v-if="props.onlyAnswer">
              {{ formData.locate }}
            </div>
            <div v-if="formData.title && !props.onlyAnswer">
              <span v-show="formData.required === '必填'" style="color: red">
                *
              </span>
              {{ formData.title }}
            </div>
          </n-row>
        </template>
        <template #description v-if="formData.remark">
          <div class="remark">
            {{ '——' + formData.remark }}
          </div>
        </template>
        <div v-if="!props.onlyAnswer && !props.onlyAnswer">
          <n-input-group v-if="!props.showDetail">
            <n-input v-model:value="formData.locate" style="width: 30%" />
            <n-button>获取定位</n-button>
          </n-input-group>
          <n-space v-else>
            {{ formData.locate }}
          </n-space>
        </div>
      </n-thing>
    </div>
  </div>
</template>

<script setup lang="ts">
import { LocationSharp as FlashIcon } from '@vicons/ionicons5';
import { ref, reactive, computed } from 'vue';

// 父组件传来的数据
const props = defineProps({
  index: {
    type: Number,
    default: 0,
  },
  title: {
    type: String,
    required: true,
  },
  required: {
    type: String,
    default: '非必填',
  },
  remark: {
    type: String,
    default: '',
  },
  locate: {
    required: true,
  },
  showDetail: {
    type: Boolean,
    defualt: false,
  },
  onlyAnswer: {
    type: Boolean,
    default: false,
  },
});

// 暂存数据
const formData: any = reactive({
  title: props.title,
  remark: props.remark,
  required: props.required,
  locate: props.locate,
});

// 双向数据绑定，子组件emit
const emit = defineEmits(['update:locate']);
const upF = (value: string) => {
  emit('update:locate', value);
};

const formRef = ref(null);
</script>

<style scoped lang="scss">
.locate-q {
  .index {
    margin-right: 1vw;
  }
  .content {
    padding: 1vw;
  }
  .title {
    font-size: 1.25rem;
  }
  .remark {
    font-size: 1rem;
    color: #999;
  }
  .edit {
    padding: 0 5vw;
  }
}
</style>
